$(document).ready(function () {
    // 图片预览
    $(".file-path").on("change",function() {
        var srcAll = getObjectURL(this.files[0]);   //获取路径
        $(this).siblings('.add-img').addClass('hide');  //this指的是input
        $(this).siblings(".back-pic").show();
        $(this).parent(".pictures-one").css("border","none");
        $(this).parent().next().children('.add-img').removeClass('hide');
        $(this).parent().next().children('.file-path').removeAttr('disabled');
        $(this).nextAll(".back-pic").attr("src",srcAll);
    });
    $(".input-img-btn").change(function(){
        var objUrl = getObjectURL(this.files[0]) ;
        if (objUrl) {
            $("#img0").attr("src", objUrl);
            // $("#img1").attr("src", objUrl);
        }
        $("#add-img-btn").addClass('hide');
        $("#logo-container").css("border","none");
    });
    // 轮播
    animate()

})
function animate(offset) {
    var list = document.getElementById('list');
    var prev = document.getElementById('prev');
    var next = document.getElementById('next');
    var newLeft = parseInt(list.style.left) + offset;
    animateImg(list,prev,next,newLeft)

}
function animateImg(list,prev,next,newLeft) {
    list.style.left = newLeft + 'px';
    if(newLeft<-304){
        list.style.left = -304 + 'px';
    }
    if(newLeft>0){
        list.style.left = 0;
    }
    prev.onclick = function() {
        animate(304);
    }
    next.onclick = function() {
        animate(-304);
    }
}
function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL !== undefined) {
        url = window.createObjectURL(file)
    } else if (window.URL !== undefined) {
        url = window.URL.createObjectURL(file)
    } else if (window.webkitURL !== undefined) {
        url = window.webkitURL.createObjectURL(file)
    }
    return url
};